CX_TIMED_TRIGGER
Class hierarchy
- CX_CLASS
- CX_TIMED_TRIGGER
Description:
An object of this class can be used to manage actions that are not to be triggered immediately, but at one or more specific times. The action consists of two steps (each optional) and is triggered at the time set with SetActionTerm:
- A start signal defined with SetMsg or SetStartEndMsg is transmitted
- An end signal defined with SetEndMsg or SetStartEndMsg is sent
With SetCycles, the maximum number of transmitted signals can also be fixed. If both start message and end message are defined, the start message is always sent before the end message.
The sent messages are always called up on the stack with the same parameters:
Position | Type | Description |
---|---|---|
Top | CX_NUMERIC | The consecutive number of the message. If it is the last message sent, then this value is equal to TimesTriggered. |
Top 1 | CX_NUMERIC | The maximum number of activations of the CX_TIMED_TRIGGER set in SetCycles If nothing has been set, this value is 0. |
top 2 | CX_TIMED_TRIGGER | The CX_TIMED_TRIGGER object that sent the message |
Application examples:
- Reproduction of an alarm clock
- Triggering a cyclic backup
- At 12.00 noon changeover from "coming" to "going" at a flexitime terminal
Code example:
Msg(COUNT_DOWN) Var(timedTrigger, dateTime) CreateTransObject(CX_TIMED_TRIGGER) -> timedTrigger // Define and set moments for sending a message CreateTransObject(CX_DATETIME) -> dateTime CreateTransObject(CX_PERIODIC_SPAN_TIME) dateTime Link(time) "1 min" dateTime Put(time.frequency) 1 dateTime Put(time.validEnum) // 0 = " from/until", 1 = "from", 2 = "until", 3 = "unlimited" dateTime timedTrigger Call(SetActionTerm) // Set message to be sent (COUNT_DOWN) timedTrigger Call(SetMsg) // Activate trigger timedTrigger Call(Activate) Window(TestWin, 10, 50, 200, 100, "Time trigger") [ INITIALIZE: 10 timedTrigger Call(SetCycles) // .... further statements COUNT_DOWN: -> triggerIndex // index of signals sent -> maxCycles // max. number of cycles set by SetCycles -> timedTrigger // the timed trigger object, which has send this message // .... further statements ] {}
The TimeTrigger runs in a separate thread. This means that it sends messages even if the main thread is busy and cannot process the messages at all. The messages are then queued until the main thread is free again and are then received. In this way, the same message from the TimeTrigger can be received relatively often within a short time. The following example code only takes into account the last message of the collected ones and ignores the others.
// create timed trigger
CreateTransObject(CX_TIMED_TRIGGER) -> timedTrigger
(TIME_TRIGGER_MESSAGE) timedTrigger Call(SetMsg)
CreateTransObject(CX_PERIODIC_SPAN_TIME, KEEP) -> tmpTime
// Set frequency in seconds
5s tmpTime Put(frequency) // fire once every 5 seconds
3 tmpTime Put(validEnum)
tmpTime timedTrigger Call(SetActionTerm)
// Activate trigger
timedTrigger Call(Activate)
// Handling duplicate messages in the trigger message
TIME_TRIGGER_MESSAGE: Integer -> tmpIndex DropAll
// only execute the last message if there are more than one in the pipe
timedTrigger Call(TimesTriggered) tmpIndex > if return
Why Start & End Message?
The final message is still a remnant from an older design of the CX_TIMED_TRIGGER class, which also allowed a method to be called on an object between the two messages. However, the call was executed in parallel, which was highly critical due to the lack of synchronization mechanisms in InstantView, and since the object was not protected from the garbage collection either, the mechanism was disabled. Since the end message is parked obsolete, it will also be removed from the interface in the near future.
Function | MA* | Parameters | Return | Brief description |
---|---|---|---|---|
Activate | INTEGER | Activating the trigger | ||
Deactivate | Deactivating the trigger without resetting the number of signals already sent | |||
DisableMsg | Resetting all messages to be sent | |||
GetActionTerm | OBJECT | Time at which a signal should be sent | ||
GetCycles | INTEGER | Output of the maximum number of periods to be run through. If zero is not specified. | ||
IsActive | INTEGER | Check whether trigger is active | ||
ResetTriggered | Deactivating the trigger with resetting the number of signals already sent | |||
SetActionTerm | OBJECT | Set the time(s) at which a signal is to be sent | ||
SetCycles | INTEGER | Fixed specification of the maximum number of periods to be run | ||
SetEndMsg | INTEGER | Set the end message to be sent | ||
SetMsg | INTEGER | Setting the (start) message to be sent | ||
SetStartEndMsg | INTEGER, INTEGER | Setting the (start) message and end message to be sent | ||
TimeToNextEvent | CX_VALUE | Time to the next signal | ||
TimesTriggered | Number of signals already transmitted | |||
Diagnostics | Information about the current state of the timed trigger - implemented for test purposes | |||
GetDomain | CX_CLASS | INTEGER | Returns the domain of the object |
Module | Brief description |
---|---|
AppsWH\Evaluate\qm\timedTrigger_qm.mod | Module for testing the functionality |